package com.wxyzz.satserver.pay.controller;


import com.wxyzz.common.core.annotation.NoLoginCheck;
import com.wxyzz.common.core.common.R;
import com.wxyzz.satserver.pay.param.OrderPayParam;
import com.wxyzz.satserver.pay.service.OrderPayService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/order")
@Api(tags ="交易订单api")
@CrossOrigin
public class OrderPayController {

    @Resource
    private OrderPayService orderPayService;

    @PostMapping("/pay")
    @ApiOperation(value = "创建支付的业务订单")
    public R createOrderPay(@RequestBody OrderPayParam param) {
        String url = orderPayService.createOrderPay(param);
        return R.ok(url);
    }

    @PostMapping("/notify")
    @ApiOperation(value = "支付宝的异步回调")
    public void orderNotify(HttpServletRequest request, HttpServletResponse response) {
        orderPayService.orderNotify(request, response);
    }

    @GetMapping("/status")
    @ApiOperation(value = "交易订单状态查询")
    public R payStatus(OrderPayParam orderPayParam) {
        orderPayService.payStatus(orderPayParam);
        return R.ok();
    }

    @GetMapping("/close")
    @ApiOperation(value = "关闭交易订单")
    public R payClose(OrderPayParam orderPayParam) {
        orderPayService.payClose(orderPayParam);
        return R.ok();
    }

    @GetMapping("/pay/return")
    @ApiOperation(value = "支付的同步回调")
    public R orderReturn(HttpServletRequest request, HttpServletResponse response) {
        orderPayService.orderReturn(request, response);
        return R.ok();
    }
}
